/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_ora_NVPair_get_value.c                           */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/15 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../../src/module/oracle/config.h"
#include <oracle/ora_core.h>
#include <oracle/comm/ora_comm.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

int ora_NVPair_get_value(Frlist_header *p_st_head, const char *p_keys, char **pp_value);

static void __case1(void)
{
    int i_ret = 0;
    Frlist_header *p_st_head = NULL;
    char *p_output = NULL;

    i_ret = ora_NVPair_get_value(p_st_head, NULL, &p_output);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
}

//没有p_st_data->value
static void __case2(void)
{
    int i_ret = 0;
    Frlist_header *p_st_head = NULL;
    Frlist_node *p_st_node = NULL;
    Ora_NVPair *p_st_data = NULL;
    char *p_output = NULL;
    
    p_st_data = (Ora_NVPair *)frmalloc(sizeof(Ora_NVPair));
    memset(p_st_data, 0x00, sizeof(Ora_NVPair));
    p_st_data->key = (char *)"DESCRIPTION.CONNECT_DATA.SID";
    
    p_st_node = frlist_node_create(p_st_data);
    
    p_st_head = frlist_create();
    p_st_head->head = p_st_node;
   
    i_ret = ora_NVPair_get_value(p_st_head, "DESCRIPTION.CONNECT_DATA.SID", &p_output);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    frfree(p_st_data);
    frfree(p_st_node);
    frfree(p_st_head);
}

static void __case3(void)
{
    int i_ret = 0;
    Frlist_header *p_st_head = NULL;
    Frlist_node *p_st_node = NULL;
    Ora_NVPair *p_st_data = NULL;
    char *p_output = NULL;
    
    p_st_data = (Ora_NVPair *)frmalloc(sizeof(Ora_NVPair));
    memset(p_st_data, 0x00, sizeof(Ora_NVPair));
    p_st_data->key = (char *)"DESCRIPTION.CONNECT_DATA.SID";
    p_st_data->value = (char *)"test";
    
    p_st_node = frlist_node_create(p_st_data);
    
    p_st_head = frlist_create();
    p_st_head->head = p_st_node;
   
    i_ret = ora_NVPair_get_value(p_st_head, "DESCRIPTION.CONNECT_DATA.SID", &p_output);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    frfree(p_st_data);
    frfree(p_st_node);
    frfree(p_st_head);
}

int add_suite_ora_NVPair_get_value(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" ora_NVPair_get_value()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
